package com.chengzzz.czsee.adapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat.startActivity
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.chengzzz.czsee.MainActivity
import com.chengzzz.czsee.R
import com.chengzzz.czsee.core.infoActivity
import com.chengzzz.czsee.fragment.infoFragment
import com.chengzzz.czsee.pojo.DataClass
import kotlinx.android.synthetic.main.activity_main.*


class videoAdapter(val videoList: DataClass) :RecyclerView.Adapter<videoAdapter.ViewHolder>(){

    inner class ViewHolder(view:View):RecyclerView.ViewHolder(view){
    val name:TextView =view.findViewById(R.id.textView)
    val pic: ImageView =view.findViewById(R.id.imageView)
    val typeName: TextView =view.findViewById(R.id.textView2)
    val director: TextView =view.findViewById(R.id.textView3)
    val year: TextView =view.findViewById(R.id.textView4)
    val area: TextView =view.findViewById(R.id.textView5)
    val update: TextView =view.findViewById(R.id.textView6)
    }
    companion object {

    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): videoAdapter.ViewHolder {
      val view = LayoutInflater.from(parent.context).inflate(R.layout.recyclelayout, parent,false)
      val viewHolder = ViewHolder(view)
        viewHolder.itemView.setOnClickListener {
            var intent = Intent(it.context, infoActivity::class.java)
            intent.putExtra("data",videoList.data[viewHolder.adapterPosition])
            it.context.startActivity(intent)
        }
        return viewHolder
    }
    override fun getItemCount(): Int = videoList.data.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.name.text = videoList.data[position].vod_name
        holder.typeName.text = videoList.data[position].vod_type
        holder.director.text = videoList.data[position].vod_language
        holder.year.text = videoList.data[position].vod_year
        holder.area.text = videoList.data[position].vod_area
        holder.update.text = videoList.data[position].vod_continu
        Glide.with(holder.itemView).load(videoList.data[position].vod_pic).into(holder.pic)
    }
    fun replaceFragment(fragment: Fragment){

    }
}